package edu.xhu.communityantiepidemicsystemback.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import edu.xhu.communityantiepidemicsystemback.dto.*;
import edu.xhu.communityantiepidemicsystemback.entity.Community;
import edu.xhu.communityantiepidemicsystemback.entity.Notice;
import edu.xhu.communityantiepidemicsystemback.mapper.NoticeMapper;
import edu.xhu.communityantiepidemicsystemback.service.INoticeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lcx
 * @since 2022-06-20
 */
@Service
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> implements INoticeService {

    @Autowired
    public NoticeMapper noticeMapper;

    //获取列表信息
    @Override
    public IPage<Notice> selectNoticeList(Query query){
        Page<Notice> page = new Page<>();
        page.setCurrent(query.getPageNO());
        page.setSize(query.getPageSize());
        return this.page(page);
    }

    //模糊查询
    @Override
    public IPage<Notice> fuzzyNoticeInfo(Fuzzy fuzzy) {
        Page<Notice> page=new Page<>();
        page.setCurrent(fuzzy.getPageNO());
        page.setSize(fuzzy.getPageSize());
        QueryWrapper<Notice> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(fuzzy.getSelect(),fuzzy.getSearchStr());
        return this.page(page,queryWrapper);
    }

    //增加
    @Override
    public boolean addNotice(CreateNotice createNotice){
        Notice notice = new Notice();
        BeanUtils.copyProperties(createNotice,notice);

        //notice.setTitle(createNotice.getTitle());
        //notice.setContent("content");
        notice.setCreateTime(LocalDateTime.now());
        //notice.setCreator("system");
        return this.save(notice);
    }


    //删除
    @Override
    public boolean delNotice(Integer id){
        return this.removeById(id);
    }

    //修改
    @Override
    public boolean updateNotice(UpdateNotice updateNotice){
        Notice notice = new Notice();
        BeanUtils.copyProperties(updateNotice,notice);
        notice.setUpdateTime(LocalDateTime.now());
        //notice.setOperator("system");
        return this.updateById(notice);
    }


}
